package com.cuit.cuiter.controller;


import Api.LoginAndRegist.LoginAndRegist;
import com.cuit.cuiter.service.LoginRegisterService;
import com.cuit.user.User;
import com.cuit.user.Vo.Register;
import com.cuit.user.request.LoginUserRequest;
import common.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@CrossOrigin
//@RefreshScope//nacos 云端改了配置之后自动刷新 不用重启
public class LoginRegisterController implements LoginAndRegist {
    @Autowired
    LoginRegisterService loginRegisterService;

    @Override
    @GetMapping("/findAll")
    public List<User> findAll() {
        return loginRegisterService.findAll();
    }

    /**
     * 用户登录
     *
     * @param loginUserRequest
     * @return
     */
    @Override
    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginUserRequest loginUserRequest) {
        return loginRegisterService.login(loginUserRequest);
    }

    /**
     * 注册
     *
     * @param user
     * @return
     */
    @Override
    @PostMapping("/register")
    public ResponseResult register(@RequestBody Register register) {
        System.out.println("进来了");
        System.out.println(register);
//        System.out.println(checkCode);
        return loginRegisterService.register( register);
    }
}
